#include "Window.h"

Window::Window(WindowID type) : Container(0, 0, NULL) {
	this->type = type;
}

void Window::add(Widget *widget) {
	Container::add(widget);
}

void Window::showOn(SDL_Surface* surface) {
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		((Widget*) *it_widget)->showOn(surface);
	}
}

void Window::handleEvent(Event event) {
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		((Widget*) *it_widget)->handleEvent(event);
	}
}

void Window::resolve() {
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		((Widget*) *it_widget)->resolve();
	}
}

Window::~Window() {
	std::list<Widget*>::iterator it;
	for (it = this->widgets.begin(); it != this->widgets.end(); it++) {
		it = this->widgets.erase(it);
	}
}

WindowID Window::getWindowType(){
	return this->type;
}

Container* Window::getScenarioContainer(){
	return container;
}

void Window::setScenarioContainer(Container* container){
	this->container = container;

	add(container);
}
